# Contributor: rubicon <rubicon@mailo.com>
# Maintainer:
pkgname=ocamlnet
pkgver=4.1.9
pkgrel=1
pkgdesc="Network and system programming library for OCaml"
url="http://projects.camlcity.org/projects/ocamlnet.html"
arch="all !riscv64" # restricted by ocaml
license="zlib-acknowledgement, BSD-3-Clause and GPL-2.0-only"
depends="ocaml-runtime"
depends_dev="$pkgname=$pkgver-r$pkgrel"
makedepends="
	ocaml
	ocaml-camlzip-dev
	ocaml-compiler-libs
	ocaml-dev
	ocaml-findlib
	ocaml-pcre-dev
	gnutls-dev
	pcre-dev
	tcl-dev
	"
subpackages="$pkgname-tcl $pkgname-dev"
source="http://download.camlcity.org/download/ocamlnet-4.1.9.tar.gz
	fix-version-number.patch
	"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	export C_INCLUDE_PATH=/usr/lib/ocaml

	./configure \
		-datadir /usr/share/"$pkgname" \
		-enable-pcre \
		-enable-gnutls \
		-enable-zip \
		-with-nethttpd \
		-enable-tcl \
		-equeue-tcl-defs -I/usr/include \
		-equeue-tcl-libs -ltcl8.6

	msg "Building Ocamlnet bytecode libraries"
	make -j1 all
	msg "Building Ocamlnet native code libraries"
	make opt
}

package() {
	export DESTDIR="$pkgdir"
	export OCAMLFIND_DESTDIR="$pkgdir"/usr/lib/ocaml
	mkdir -vp "$pkgdir"/usr/share/"$pkgname" \
		"$OCAMLFIND_DESTDIR"/stublibs
	make install
}

tcl() {
	pkgdesc="$pkgdesc (Tcl event system)"
	amove usr/lib/ocaml/equeue-tcl \
		usr/lib/ocaml/stublibs/dllequeue_tcl*
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; for path in $(find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.cmx' -o \
			-name '*.cmxa' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\))
	do
		amove "$path"
	done
}

sha512sums="
a251724deb35e756c81d2d3ac836d413b659acdce6c0acf479a4fca48934ab62ad399a884197d00dbb7e7558132a56be1c8efd553c0a644d329418272f809a46  ocamlnet-4.1.9.tar.gz
0fd0e8e51229a126ebf96fdac957d2ed69e8b3511b11b2d0a7b6d4a6f77018a4f79370f59f5ce460ad5847dc727cdddce96b2aa1da7180baff1245aee35939f4  fix-version-number.patch
"
